from pathlib import Path
from loguru import logger

# 确保日志目录存在
log_dir = Path("logs")
log_dir.mkdir(exist_ok=True)

# 移除默认的 sink
logger.remove()

# 添加文件日志
logger.add(
    "logs/app.log",
    rotation="10 MB",
    retention="1 week",
    format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}",
    level="INFO",
    enqueue=True
)

def get_logger(name: str):
    """获取带有上下文的日志记录器"""
    return logger.bind(name=name) 